/*   
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.   
 *   
 * This software is the confidential and proprietary information of   
 * DMGIS. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with DMGIS.   
 *   
 */
package com.dmgis.qxfw.dataservice.businessservice.common.util;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;

import java.io.IOException;

/**
 * This class is used for 共享文件读取
 * 
 * @author dsq
 * @version 1.0, 2018年7月18日 下午10:49:47
 */
public class SmbFileUtil {
	private final String username = "DMGIS_CS";
	private final String password = "dmgis@123456";
	private NtlmPasswordAuthentication auth = null;
	private SmbFile smbFile = null;

	/**
	 * 默认用户名和密码
	 */
	public SmbFileUtil() {
		auth = new NtlmPasswordAuthentication(null, this.username, this.password);
	}

	/**
	 * 初始化用户名密码
	 * @param username
	 * @param password
	 */
	public SmbFileUtil(String username, String password) {
		auth = new NtlmPasswordAuthentication(null, username, password);
	}

	public SmbFile getSmbFile(String path) {
		try {
			smbFile = new SmbFile("smb:" + path, auth);
			smbFile.connect();
			if (smbFile.isFile()) {
				return smbFile;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return smbFile;
	}
}
